package
{
	/**
	 * @author LeeXiangwei
	 * @date 2013.2.14
	 * @since v1.0
	 * 初始化棋盘和棋子地形布局，棋子移动到棋盘空白处的实现方法。
	 */
	import flash.display.BitmapData;
	import flash.display.GraphicsPathCommand;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.system.Security;
	
	import game.DecuryMan.DecuryMan;
	import game.DecuryMan.Lake;
	import game.DecuryMan.GreenPoints;
	import game.DecuryMan.Mountain;
	import game.DecuryMan.RedOwn;
	
	import mx.controls.Alert;
	import mx.core.IVisualElement;
	
	import spark.components.Group;
	import spark.core.SpriteVisualElement;

	public class ChessMain extends SpriteVisualElement
	{
		
		public static var game:Object;
		
		public static var player:int = 0; //0代表玩家1  1代表玩家2  2代表旁观者
		
		
		public static const IMGDIR1:String = "imgs/chinablack/";
		public static const IMGDIR2:String = "imgs/chinawhite/";
		public static const IMGDIR3:String = "imgs/mountain/";  //高山图片路径
		public static const IMGDIR4:String = "imgs/lake.jpg";
		
		public static var MANS_START:Array = new Array(0,10);
		public static var IMGDIR_ARR:Array = new Array("imgs/chinablack/","imgs/chinawhite/");
		
		//定义一些游戏状态
		public static const READY:int = 1; //准备状态
		public static const LAYOUT:int = 2; //布局状态
		
		//当前选中的棋子，只有一个棋子处于选中状态
		public static var selectedDecuryman:DecuryMan = null;
		
		//一方被吃掉的棋子
		public static var redDead:Array = new Array(10);
		
		//另一方被吃掉的棋子
		public static var blackDead:Array = new Array(10);
		//初始的等级分配
		public static var levle:Array = new Array(0,0,0,0,0, 1,2,3,4,5);
		
		//存储棋子的level
		public static const mapArr:Array = new Array(
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
		);
		
		//存储绿点对象
		public static const greenPoints = new Array(
			new Array(10),
			new Array(10),
			new Array(10),
			new Array(10),
			new Array(10),
			new Array(10),
			new Array(10),
			new Array(10),
			new Array(10),
			new Array(10)
		);
		//存储图标对象
		public static const terrianFlag = new Array(
			new Array(10),
			new Array(10),
			new Array(10),
			new Array(10),
			new Array(10),
			new Array(10),
			new Array(10),
			new Array(10),
			new Array(10),
			new Array(10)
		);
		//存储上一次走棋的棋子，本次不能在走棋
		public static var lastMoveMan:Array=new Array(null,null,null);
		//存储高山湖泊信息    0表示无地形，1代表高山，-1代表湖泊
		public static const terrian:Array = new Array(
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
		);
		//存储高山湖泊遍历信息，0代表没有遍历过，1代表遍历过
		public static const terrianJudge:Array = new Array(
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0),
			new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
		);

		public static var startZone1:Array = new Array(
			10,5,8,5,8,8,5,8,5,10
		);
		public static var startZone2:Array = new Array(
			0,5,2,5,2,2,5,2,5,0
		);
		
		//图片资源数组
		public static const imgArr:Array = new Array(
			"Ab.png","Cs.png","Eq.png","Pr.png","Tr.png","Se.png"
		);
		
		
		//棋盘的宽度
		public static var BW:int;
		//棋子的宽度
		public static var gridW:int = 60;
		
		//高山位置
		public var mountainPosArr:Array = new Array(
			27,37,47,36,46,56
			);
		
		//湖泊位置
		public var lakePosArr:Array=new Array(
			42,44,53
			);
		
		//玩家1和2 棋子在棋盘上的初始位置
		public var piecesPosArr:Array = new Array(
			0,1,2,3,4, 10,11,12,13,14,
			85,86,87,88,89, 95,96,97,98,99
		);
		
		
		public static var manArr:Array = new Array(20);
		
//		public var manArr1:Array = new Array(10);
//		public var manArr2:Array = new Array(10);
		
		//玩家1的  开始布局区域线条
		private var zoneline1:Sprite=new Sprite();
		private var zoneline2:Sprite=new Sprite();
		
		//显示鼠标经过时的方框位置(蓝色方框)
		public static var showPos:Sprite = new Sprite();
		//显示选择的棋子（绿色方框）
		public static var showSelected:Sprite = new Sprite();
		
		public static var selectedLevel:int;
		
		//所有的初始化都应该放到init方法中
		public function ChessMain(g:Group)
		{
			Security.allowDomain("*");
			this.buttonMode = true;
			this.useHandCursor = true;
			
			this.width = 600;
			this.height = 600;
			game = g;
			var board:Loader = new Loader();
			board.load(new URLRequest("imgs/Decury-backup.jpg"));
			
			//Alert.show(mapArr[0][1] + " ");
			this.addChild(board);
			BW = board.width;
			
			//初始化双方 的棋子
			initPieces();
			//初始化高山
			iniMountain();
			//初始化湖泊
			iniLake();
			//初始化绿点
			iniGreenPoints();
			//绘制 初试的布局 区域
			this.drawLine(startZone1,zoneline1);
			this.drawLine(startZone2,zoneline2);
			
			//添加蓝色方框 跟随鼠标
			this.addEventListener(MouseEvent.MOUSE_MOVE,move );
			
			//蓝色，显示当前鼠标所在的方框
			showPos.graphics.lineStyle(2,0x0000ff);
			showPos.graphics.drawRect(0,0,60,60);
			//绿色，显示选择棋子的位置
			showSelected.graphics.lineStyle(2,0x00ff00);
			showSelected.graphics.drawRect(0,0,60,60);

			
		}
		//初始化绿点对象
		private function iniGreenPoints():void{
			for(var i:int=0;i<100;i++)
			{
				var greenPointRow:int=i/10;
				var greenPointCol:int=i%10;
				var green:GreenPoints=new GreenPoints();
				green.define(greenPointCol*gridW,greenPointRow*gridW);
				greenPoints[greenPointRow][greenPointCol]=green;
			}
		}
		
		//初始化高山
		private function iniMountain():void{
			var len:int=mountainPosArr.length;
			for(var i:int=0;i<len;i++)
			{
				var mountain:Mountain=new Mountain();
				var row:int=mountainPosArr[i]/10;
				var col:int=mountainPosArr[i]%10;
				mountain.x=col*gridW;
				mountain.y=row*gridW;
				mountain.load(new URLRequest(IMGDIR3 + (int)(i+1) +"mountain.png"));
//				Alert.show(IMGDIR3 + (int)(i+1) +"mountain.png");
				terrian[row][col]=1;
				this.addChild(mountain);
			}
		}
		
		//初始化湖泊
		private function iniLake():void{
			var len:int=lakePosArr.length;
			for(var i:int=0;i<len;i++)
			{
				var lake:Lake=new Lake();
				var row:int=lakePosArr[i]/10;
				var col:int=lakePosArr[i]%10;
				lake.x=col*gridW;
				lake.y=row*gridW;
				lake.load(new URLRequest(IMGDIR4));
//				Alert.show(IMGDIR4);
				terrian[row][col]=-1;
				this.addChild(lake);
			}
		}
		/**
		 * 根据balckPosArr，whitePosArr所定义的棋子初始位置来初始化双方的棋子
		 * */
		private function initPieces():void{
			
			for(var i:int=0; i<20; i++){
				var man:DecuryMan = new DecuryMan();
				var row:int = piecesPosArr[i] / 10;
				var col:int = piecesPosArr[i] % 10;
				man.col=col;
				man.row=row;
				man.x = col * gridW;
				man.y = row * gridW;
				man.pos = piecesPosArr[i];
				man.index = i+1; // index从1开始
				
				
				if(i < 10){
//					man.level = i%5+1;
					man.level = levle[i%5];
					man.load(new URLRequest(IMGDIR1 + (i%5+1) + imgArr[levle[i%5]]));					
				}
				else{
					man.level = -levle[i%5+5]; //玩家2的level是负的
					man.load(new URLRequest(IMGDIR2 + (i%5+1) + imgArr[levle[i%5+5]]));
				}
				
				man.setRules(i%5);//设置棋子移动规则
				
				mapArr[row][col] = man.level; //存储 棋子的level 玩家2小于0
					
				manArr[i] = man;
				this.addChild(man);
				
			}
	
		}
		

		
		//判断棋子移动和攻击规则
		private function passJudge(decury:DecuryMan,column:int,row:int):Boolean
		{
			if(decury.row==row)
			{
				if(Math.abs(decury.col-column)>1)
				{
					if(decury.isCross==false) return false;
					for(var i:uint=Math.min(decury.col,column)+1;i<Math.max(decury.col,column);i++)
					{
						if(0!=mapArr[row][i])						
							return false;
						switch (terrian[row][i])
						{
							case 1:return false;break;
							case -1:return false;break;
							case 2:if(decury.level>0)return true;else return false;break;
							case 3:if(decury.level<0)return true;else return false;break;
							case -2:if(decury.level>0)return true;else return false;break;
							case -3:if(decury.level<0)return true;else return false;break;
						}
					}
					if(0!=mapArr[row][column])
					{
						if(mapArr[row][column]*decury.level>0)
							return true	;											//形成棋堆
						else
						{
							if(decury.isCrossAttack)
								return true;
							else return false;
						}
					}
					else
						return true;
				}
				else
				{			
					return true;
				}
			}
			else if(decury.col==column)
			{
				if(Math.abs(decury.row*10+decury.col-row*10-column)>10)
				{
					if(decury.isCross==false) return false;
					for(var i:uint=Math.min(decury.row,row)+1;i<Math.max(decury.row,row);i++)
					{
						if(0!=mapArr[i][column])
							return false;
						switch (terrian[i][column])
						{
							case 1:return false;break;
							case -1:return false;break;
							case 2:if(decury.level>0)return true;else return false;break;
							case 3:if(decury.level<0)return true;else return false;break;
							case -2:if(decury.level>0)return true;else return false;break;
							case -3:if(decury.level<0)return true;else return false;break;
						}
					}
					if(0!=mapArr[row][column])
					{
						if(mapArr[row][column]*decury.level>0)
							return true	;											//形成棋堆
						else
						{
							if(decury.isCrossAttack)
								return true;
							else return false;
						}
					}
					else
						return true;
					
				}
				else
				{			
					return true;
				}
			}
			else if(Math.abs(decury.row-row)==Math.abs(decury.col-column))
			{
				//					mx.controls.Alert.show(Math.abs((row*10+column)-(decury.row*10+decury.column))+" ")
				if(Math.abs((row*10+column)-(decury.row*10+decury.col))%9==0)
				{
					if(Math.abs((row*10+column)-(decury.row*10+decury.col))==9) 
					{
						if(column<decury.col)
						{
							if(terrian[decury.row+1][decury.col]<0&&terrian[decury.row][decury.col-1]<0)
							{
								switch(terrian[decury.row+1][decury.col])
								{
									case -1:return false;break;
									case -2:if(decury.level>0)return true;else return false;break;
									case -3:if(decury.level<0)return true;else return false;break;
								}
							}	
							return true;
						}
						else
						{
							if(terrian[decury.row-1][decury.col]<0&&terrian[decury.row][decury.col+1]<0)
							{
								switch(terrian[decury.row-1][decury.col])
								{
									case -1:return false;break;
									case -2:if(decury.level>0)return true;else return false;break;
									case -3:if(decury.level<0)return true;else return false;break;
								}
							}
							return true;
						}
					}
					else
					{
						if(decury.isBias==false) return false;
						var min:uint=Math.min((row*10+column),(decury.row*10+decury.col));
						var max:uint=Math.max((row*10+column),(decury.row*10+decury.col));
						if(terrian[(uint)((min-1)/10)][(uint)((min-1)%10)]<0&&terrian[(uint)((min+10)/10)][(uint)((min+10)%10)])
							{
								switch(terrian[(uint)((min-1)/10)][(uint)((min-1)%10)])
								{
									case -1:return false;break;
									case -2:if(decury.level>0)return true;else return false;break;
									case -3:if(decury.level<0)return true;else return false;break;
								}
							}
						for(var i:uint=min+9;i<max;i+=9)
						{//mx.controls.Alert.show("min"+min+"  "+"max"+max+"  "+(uint)(i/10)+"  "+i%10);
							if(0!=mapArr[(uint)(i/10)][i%10])
								return false;
							switch (terrian[(uint)(i/10)][i%10])
							{
								case 1:return false;break;
								case -1:return false;break;
								case 2:if(decury.level>0)return true;else return false;break;
								case 3:if(decury.level<0)return true;else return false;break;
								case -2:if(decury.level>0)return true;else return false;break;
								case -3:if(decury.level<0)return true;else return false;break;
							}
							if(terrian[(uint)((i+10)/10)][i%10]<0&&terrian[(uint)(i/10)][(i-1)%10]<0)
							{
								switch(terrian[(uint)((i+10)/10)][i%10])
								{
									case -1:return false;break;
									case -2:if(decury.level>0)return true;else return false;break;
									case -3:if(decury.level<0)return true;else return false;break;
								}
							}
							
						}
						if(0!=mapArr[row][column])
						{
							if(mapArr[row][column]*decury.level>0)
								return true	;											//形成棋堆
							else
							{
								if(decury.isBiasAttack)
									return true;
								else return false;
							}
						}
						else
							return true;
					}
				}
				if(Math.abs((row*10+column)-(decury.row*10+decury.col))%11==0)
				{
					if(Math.abs((row*10+column)-(decury.row*10+decury.col))==11) 
					{
						if(column<decury.col)
						{
							if(terrian[decury.row-1][decury.col]<0&&terrian[decury.row][decury.col-1]<0)
						 	{
								switch(terrian[decury.row-1][decury.col])
								{
									case -1:return false;break;
									case -2:if(decury.level>0)return true;else return false;break;
									case -3:if(decury.level<0)return true;else return false;break;
								}
						 	}	
							return true;
						}
						else
						{
							if(terrian[decury.row+1][decury.col]<0&&terrian[decury.row][decury.col+1]<0)
							{
								switch(terrian[decury.row+1][decury.col])
								{
									case -1:return false;break;
									case -2:if(decury.level>0)return true;else return false;break;
									case -3:if(decury.level<0)return true;else return false;break;
								}
							}
							return true;
						}						
					}
					else
					{
						if(decury.isBias==false) return false;
						var min:uint=Math.min((row*10+column),(decury.row*10+decury.col));
						var max:uint=Math.max((row*10+column),(decury.row*10+decury.col));
						if(terrian[(uint)((min+1)/10)][(uint)((min+1)%10)]<0&&terrian[(uint)((min+10)/10)][(uint)((min+10)%10)])
						{
							switch(terrian[(uint)((min+1)/10)][(uint)((min+1)%10)])
							{
								case -1:return false;break;
								case -2:if(decury.level>0)return true;else return false;break;
								case -3:if(decury.level<0)return true;else return false;break;
							}
						}
						for(var i:uint=min+11;i<max;i+=11)
						{
							if(0!=mapArr[(uint)(i/10)][i%10])
								return false;
							switch (terrian[(uint)(i/10)][i%10])
							{
								case 1:return false;break;
								case -1:return false;break;
								case 2:if(decury.level>0)return true;else return false;break;
								case 3:if(decury.level<0)return true;else return false;break;
								case -2:if(decury.level>0)return true;else return false;break;
								case -3:if(decury.level<0)return true;else return false;break;
							}
							if(terrian[(uint)((i+10)/10)][i%10]<0&&terrian[(uint)(i/10)][(i+1)%10]<0)
							{
								switch(terrian[(uint)((i+10)/10)][i%10])
								{
									case -1:return false;break;
									case -2:if(decury.level>0)return true;else return false;break;
									case -3:if(decury.level<0)return true;else return false;break;
								}
							}
						}
						if(0!=mapArr[row][column])
						{
							if(mapArr[row][column]*decury.level>0)
								return true	;											//形成棋堆
							else
							{
								if(decury.isBiasAttack)
									return true;
								else return false;
							}
						}
						else
							return true;
						
					}
				}
			}
			else return false;
			return false;
		}
		//点击棋盘的事件。（可能点击棋子，也可能没点击）
		public function manClick(evt:MouseEvent):void{
			var targetColumn:int = this.mouseX / gridW;
			var targetRow:int = this.mouseY / gridW;
			
			//如果还没有选择棋子
			if(!selectedDecuryman){
				return;
			}
			else if(0==mapArr[targetRow][targetColumn]&&terrian[targetRow][targetColumn]>=0)
			{            	//如果已经选中了棋子
//				Alert.show("aa");
//				Alert.show(selectedDecuryman.col+"  "+selectedDecuryman.row+"  "+targetColumn+"  "+targetRow);
//				Alert.show(selectedDecuryman.isCross+"  "+selectedDecuryman.isCrossAttack+"  "+selectedDecuryman.isBias+"  "+selectedDecuryman.isBiasAttack)
				if(passJudge(selectedDecuryman,targetColumn,targetRow))
					{
						selectedDecuryman.x = targetColumn * gridW;
						selectedDecuryman.y = targetRow * gridW;			
						selectedDecuryman.pos = targetRow*10 + targetColumn;				
						selectedDecuryman.scaleX = 1;
						selectedDecuryman.scaleY = 1;
						selectedDecuryman.moveFlag(false);
						for(var i:int=0;i<3;i++)
						{
							
							if(null!=lastMoveMan[i])
							{
								lastMoveMan[i].moveFlag(true);
								lastMoveMan[i]=null;
							}
							
						}
						lastMoveMan[0]=selectedDecuryman;
						//更新地图的数组
						mapArr[targetRow][targetColumn] = selectedDecuryman.level;
									
				
						//说明是从棋堆 选了一个棋子. 需要把棋堆的另一个棋子恢复 正大小常。
						if(mapArr[selectedDecuryman.row][selectedDecuryman.col] > 100 )
						{
							var i:int = mapArr[selectedDecuryman.row][selectedDecuryman.col] / 100;
							var j:int = mapArr[selectedDecuryman.row][selectedDecuryman.col] % 100;
							//var remainStack:int;
							if(i == selectedDecuryman.index)
								i = j;
								--i;			
							//manArr[i]就是棋堆 剩下的那个棋子
							manArr[i].x = selectedDecuryman.col * gridW;
							manArr[i].y = selectedDecuryman.row * gridW;
							manArr[i].scaleX = 1;
							manArr[i].scaleY = 1;					
							showSelected.scaleX = 1;
							showSelected.scaleY = 1;
							showSelected.x = manArr[i].x;
							showSelected.y = manArr[i].y;	
							mapArr[selectedDecuryman.row][selectedDecuryman.col]=manArr[i].level;
							selectedDecuryman.col = targetColumn;
							selectedDecuryman.row = targetRow;							
							selectedDecuryman = null; //走完棋后 当前选择的棋子为null
							this.removeChild(showSelected);
						}
						else{
						//走棋后要更新该棋子  在棋盘上的坐标
						mapArr[selectedDecuryman.row][selectedDecuryman.col]=0;
						selectedDecuryman.col = targetColumn;
						selectedDecuryman.row = targetRow;							
						selectedDecuryman = null; //走完棋后 当前选择的棋子为null
						this.removeChild(showSelected);
						}
					}
				else 
				{
					selectedDecuryman=null;
					this.removeChild(showSelected);
				}
			}
		}
		
		public function hasComLayout():Boolean{
			//检测是否  分配等级完成! ？？
			for(var i:int=0; i<5; i++){
				if(manArr[10*player + i].level == 0){
					Alert.show("还有未分配等级的棋子!");
					return false;
				}
			}
			return true;
		}
		
		//布局完成，同时检测分配等级是否完成。 没有完成则返回。
		//同时游戏开始
		public function comLayout():Boolean{
			
			for(var i:int=MANS_START[player]; i<MANS_START[player]+10; i++)
				manArr[i].removeDrag();
			
			//对玩家的棋子添加 移动事件
			for(var i:int=MANS_START[player]; i<MANS_START[player]+10; i++)
				manArr[i].startMove();
			
			//停止 布局框 的布局功能
			game.levelSprite.stopLevelSet();
			
			// 布局完成，添加点击棋盘的事件
			this.addEventListener(MouseEvent.CLICK, manClick);
			
			this.removeChild(zoneline1);
			this.removeChild(zoneline2);
			return true;
		}
		
		
		//重置 棋子的等级
		public function manReset():void{
			for(var i:int=MANS_START[player]; i<MANS_START[player] + 10; i++)
				manArr[i].reset();
			
			game.levelSprite.levelReset();
		}
		
		
		//鼠标跟随，显示是哪个方框被选中
		public function move(evt:MouseEvent){
			//Alert.show(evt.localX + " ");
			//showPos.graphics.clear();
			
			var col:int = this.mouseX/gridW; 
			var row:int = this.mouseY/gridW;
			
			if(col > 9){
				col = 9;
			}
			if(row>9)
				row=9;
			
			showPos.x = col * gridW;
			showPos.y = row* gridW;
			this.addChild(showPos);
		}
		
		//最初的初始化 。 初始化棋子之类的, 棋盘之类
		public function init(p:int):void{
			
		}
		
		//初始化游戏《 1、初始化棋子位置和初试布局   2、可布局  3、可分配等级 》。 p为0就是玩家1.  
		public function initGame(p:int):void{
			player = p;
			//1 假设第一步已完成  由init()完成
			
			//3 可分配等级
			//game.levelSprite.initLevel(p);
			game.levelSprite.startLevelSet();
			
			//2、可布局 
			this.layoutStart();
			
		}
		
		
		//画玩家1的 布局区域
		public function drawLine(arr:Array,line:Sprite):void{
			var len:int = arr.length;
			line.graphics.lineStyle(3, 0xff0000, 0.5);
			for(var i:int = 0; i<len; i += 2){
				if(i == 0)
					line.graphics.moveTo(arr[1] * gridW, arr[0] * gridW);
				else
					line.graphics.lineTo(arr[i+1] * gridW, arr[i] * gridW);
			}
			this.addChild(line);
		}
		
		//开始布局，为每个棋子(自己的棋子)添加 拖动事件
		public function layoutStart():void{
			for(var i:int=MANS_START[player]; i<MANS_START[player] + 10; i++)
				manArr[i].addDrag();
			
		}
		
		public  function setPos(posStr:String):void{
			
			var posArr:Array = posStr.split(",");
			//Alert.show("更新位置：" + posArr[1]);
			
			for(var i:int=0; i<20; i++){
				var pos:int = posArr[i];
				var row:int = pos/10;
				var col:int = pos%10;
				manArr[i].x = col * gridW;
				manArr[i].y = row * gridW;
			}
		}
		
	}
}


